package com.zzw.controller;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzw.dao.VenueDao;
import com.zzw.model.Venue;
import com.zzw.model.VenueQuery;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/yunji-api/venue")
public class VenueController {
    @Resource
    private VenueDao venueDao;

    @PostMapping("/insert")
    public Integer insert(@RequestBody Venue venue) {
        return venueDao.insert(venue);
    }

    @GetMapping("/select")
    public PageInfo<Venue> select(VenueQuery query) {
        if (ObjectUtil.isNotEmpty(query.getPageNum()) && ObjectUtil.isNotEmpty(query.getPageSize())) {
            PageHelper.startPage(query.getPageNum(), query.getPageSize());
        }
        List<Venue> venues = venueDao.select(query);
        return new PageInfo<>(venues);
    }

    @DeleteMapping("/delete")
    public Integer delete(@RequestParam Integer id) {
        return venueDao.delete(id);
    }

    @PutMapping("/update")
    public Integer update(@RequestBody Venue venue) {
        return venueDao.update(venue);
    }

}
